package demo2;

import java.util.Objects;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-17
 */
public class Person {
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void action() {
        System.out.println(name + "正在走路");
    }

    @Override
    public boolean equals(Object obj) {
        //判空
        if (obj == null) {
            return false;
        }
        //检测地址
        if (obj == this) {
            return true;
        }

        if (obj instanceof Person) {
            Person tmp = (Person)obj;
            return tmp.name.equals(this.name) && tmp.age == this.age;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.name, this.age);
    }
}
